	<script type="text/javascript">
	//<![CDATA[

	function onFBLoggedIn(){
		console.log("onFBLoggedIn");
		$(location).attr('href',"/login/fbconnect?fb_email=" + QP.FaceBookConnect.User.email);
	}

	function onFBLoggedOut(){
		console.log("onFBLoggedOut");
		$(".facebutton").show();
	}
	
	// execute your scripts when the DOM is ready. this is a good habit
	$(document).ready(function() {	
		
		// si hay parametro enseño la ventana
		if(QP.utils.getParameterByName("fb_window") == "true"){
			if(console) console.log("fb_window true!");
			QP.Affiliate.init(QP.FaceBookConnect.User);
		}

		// inicializo
		QP.FaceBookConnect.init(false,"#facebook-connect-button",onFBLoggedIn,onFBLoggedOut);

		// si vamos a consolidar
		if("index" == "fbconsolidate"){
			if(QP.FaceBookConnect.User.getCachedUser()){
				$("#fb_id").val(QP.FaceBookConnect.User.uid);
				$(".facebutton").hide();
			}
		}

		// select all desired input fields and attach tooltips to them
		$(".form-tooltip [rel='tooltip']").tooltip({	
		
			onBeforeShow: function() {
				//console.log(this.getTip());
				if (this.getTip().html().indexOf('class="cierre"')<=-1) {
					this.getTip().append('<div class="cierre"/>');
				}
			},
			// place tooltip on the right edge
			position: "center right",
			// a little tweaking of the position
			// offset: [-2, 10],
			// use the built-in fadeIn/fadeOut effect
			effect: "toggle",
			// custom opacity setting
			opacity: 1.0		
		});
		$.tools.validator.localize("es",{
			'*' : 'Por favor corrige este valor',
			'[required]' : 'Por favor completa este campo obligatorio',
			':email' : 'Por favor introduce un email válido',
			':number' : 'Por favor introduce un valor numérico',
			':url' : 'Por favor introduce una url válida',
			'[max]' : 'Por favor introduce un valor mayor a $1',
			'[min]' : 'Por favor introduce un valor menor a $1'
		});

		$(".form-validator").validator({			
			 message: '<div/>',
				lang: 'es',
				onFail:function(){
					setTimeout(function(){
						$(".error div.cierre").remove();
						
						//console.log($('.error'));
						if ($(".error").html().indexOf('class="cierre"')<=-1) {
							$('<div class="cierre"/>').insertAfter($('.error p'));
						}
					},2);
				}
		});

	});

	//]]>
	</script>